#include <uiResourceManager.h>

namespace lgb_gtk
{

  UiResourceManager *UiResourceManager::instance = NULL;
  
  UiResourceManager::UiResourceManager()
  {
    
  }

  UiResourceManager::~UiResourceManager()
  {

  }
  
  UiResourceManager *UiResourceManager::GetInstance()
  {
    if(NULL == UiResourceManager::instance)
      UiResourceManager::instance = new UiResourceManager();
    return UiResourceManager::instance;
  }

  GdkPixbuf *UiResourceManager::LoadImageFile(std::string filePath)
  {
    if(NULL != pixbufDatas[filePath])
      return pixbufDatas[filePath];
    else
      {
	GdkPixbuf *buf = gdk_pixbuf_new_from_file(filePath.c_str() , NULL);
	if(NULL != buf)
	  pixbufDatas[filePath] = buf;
	return buf;
      }
  }

  GdkPixbuf *UiResourceManager::CreatePixbuf(std::string filePath)
  {
    GdkPixbuf *buf = LoadImageFile(filePath);
    if(NULL != buf)
      return gdk_pixbuf_copy(buf);
    else
      return NULL;
  }

  GdkPixbuf *UiResourceManager::CreatePixbufInScale(std::string filePath , double scale)
  {
    GdkPixbuf *buf = LoadImageFile(filePath);
    if(NULL == buf)
      return NULL;

    double width(0) , height(0) ;
    //g_object_get(buf , "width" , &width , "height" , &height , NULL);
    width = gdk_pixbuf_get_width(buf);
    height = gdk_pixbuf_get_height(buf);
    width *= scale;
    height *= scale;
    buf = gdk_pixbuf_scale_simple(buf , width , height , GDK_INTERP_BILINEAR );
    return buf;
  }

  GdkPixbuf *UiResourceManager::CreatePixbufInFixedArea(std::string filePath , double width , double height)
  {
    GdkPixbuf *buf = LoadImageFile(filePath);
    if(NULL == buf)
      return NULL;
    buf = gdk_pixbuf_scale_simple(buf , width , height , GDK_INTERP_BILINEAR );
    return buf;
  }


}
